package com.hxf.service.meal.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.hxf.common.PublicUtil;
import com.hxf.dto.MealBoxDto;
import com.hxf.dto.RestaurantDto;
import com.hxf.dto.ReturnData;
import com.hxf.exception.DaoLevelException;
import com.hxf.exception.ServiceException;
import com.hxf.service.base.impl.BaseServiceImpl;
import com.hxf.service.meal.MealBoxService;

@Repository("mealBoxService")
public class MealBoxServiceImpl extends BaseServiceImpl implements MealBoxService {

	@Override
	public ReturnData<MealBoxDto> findByMealBoxPage(MealBoxDto mealBoxDto, int targetPage, int pageSize) throws ServiceException { 
		try {
			return super.daoFacade.getMealBoxDao().findByMealBoxPage(mealBoxDto, targetPage, pageSize);
		} catch (DaoLevelException e) {
			throw new ServiceException(e.getMessage(), e);
		}
	}

	@Override
	public int updateMealBox(String ids, Integer status)
			throws ServiceException {
		try { 
			if (PublicUtil.isNotNullAndEmpty(ids)) {
				String [] id  = ids.split(",");
				MealBoxDto rdto = null;
				for (String rid : id) {
					rdto = (MealBoxDto)super.daoFacade.getMealBoxDao().get(MealBoxDto.class, Integer.parseInt(rid)); 
					rdto.setAuditStatus(status);
					super.update(rdto);
				}
			} else {
				return -1;
			}
			return 0;
		} catch (DaoLevelException e) {
			throw new ServiceException(e.getMessage(), e); 
		} 
	}

	@Override
	public List<MealBoxDto> findByMealBox(MealBoxDto mealBoxDto) throws ServiceException {
		 try {
			return super.daoFacade.getMealBoxDao().findByMealBox(mealBoxDto);
		} catch (DaoLevelException e) {
			throw new ServiceException(e.getMessage(), e);
		} 
	}
	
}
